package com.clarte.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;


@Entity
public class Role  implements Serializable{

	private static final long serialVersionUID = 2061990211273458298L;
	@Id
	@GeneratedValue
	private Integer id;
	@Column(unique=true,nullable=false)
	private String code;
	private String name;
	
	@ManyToMany(mappedBy="roles")
	@Fetch(FetchMode.SUBSELECT)
	private Set<User> users;
	@ManyToMany(cascade=CascadeType.ALL)
	@Fetch(FetchMode.SUBSELECT)
	private Set<Rights> rights;
	
	public Set<Rights> getRights() {
		return rights;
	}
	public void setRights(Set<Rights> rights) {
		this.rights = rights;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String roleCode) {
		this.code = roleCode;
	}
	public String getName() {
		return name;
	}
	public void setName(String roleName) {
		this.name = roleName;
	}
	public Set<User> getUsers() {
		return users;
	}
	public void setUsers(Set<User> users) {
		this.users = users;
	}
}
